package cn.highedu.spring;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan("cn.highedu.spring")
public class DITest {
    ApplicationContext context;
    @BeforeEach
    public void createContext() {
        context = new AnnotationConfigApplicationContext(DITest.class);
    }

    @Test
    public void test1() {
        // 获取被Spring管理的对象Hero
        Hero hero = context.getBean(Hero.class);
        System.out.println(hero);
        hero.hello();
    }
}
